/* * Copyright (C) 2021 Huawei Device Co., Ltd.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zhouyou.http.model;

import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

public class HttpParamsTest {

    @Test
    public void put() {
        HttpParams httpParams = new HttpParams();
        httpParams.put("key", "zhangsan");
        httpParams.put("key1", "lisi");
        String params = httpParams.toString();
        assertTrue("httpParams is not  correct", params.equals("key=zhangsan&key1=lisi"));
    }

    @Test
    public void testPut() {
        Map<String, String> params= new HashMap<>();
        params.put("key", "zhangsan");
        params.put("key1", "lisi");
        HttpParams httpParams = new HttpParams();
        httpParams.put(params);
        String paramsStr = httpParams.toString();
        assertTrue("httpParams is not  correct", paramsStr.equals("key=zhangsan&key1=lisi")||paramsStr.equals("key1=lisi&key=zhangsan"));

    }


    @Test
    public void putFileParams() {

        List<File> files=new ArrayList<>();
        files.add(new File("test.txt"));
        HttpParams httpParams = new HttpParams();
        httpParams.putFileParams("key123",files,null);
        String paramsStr = httpParams.toString();
        assertTrue("httpParams is not  correct", paramsStr.equals("key123=[FileWrapper{countent=test.txt, fileName='test.txt, contentType=text/plain, fileSize=0}]"));

    }

}